package GUI.gameWinOld;

import game.GameBoard;

import java.awt.Color;
import java.util.LinkedList;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import GUI.gameWin.CardHorizontalLayout;

import carddeck.Card;
import carddeck.CardDeck;

@SuppressWarnings("serial")
public class UsedCardPanel extends JPanel implements CardPanelInterface {
	private CardDeck usedCards;
	private GameBoard gameHandler;
	public UsedCardPanel(GameBoard game, CardDeck usedCards) {
		super();
		gameHandler = game;
		this.usedCards=usedCards;
		setBorder(new TitledBorder(usedCards.getCardCount()+" kart"));
		((TitledBorder) getBorder()).setTitleColor(Color.WHITE);
		setBackground(new Color(0, 77, 0));
		setLayout(new CardHorizontalLayout(15));
		setVisible(true);
		setOpaque(true);
	}
	
	public void updateBorder() {
		((TitledBorder) getBorder()).setTitle(usedCards.getCardCount()+" kart");
		revalidate();
	}
	
	@Override
	public void refresh() {
		removeAll();
		LinkedList<Card> usedList = usedCards.getCards();
		updateBorder();
		if(usedList.size()==0)
			return;
		int i;
		if(usedList.size()<5)
			i=0;
		else
			i=usedList.size()-5;
		for (; i<usedList.size()-1;i++) {
			Card theCard = usedList.get(i);
			CardButton theButton = new CardButton(null, gameHandler, theCard, false, true);
			add(theButton);
		}
		Card theCard = usedList.getLast();
		CardButton theButton = new CardButton(null, gameHandler, theCard, true, true);
		add(theButton);
		revalidate();
		repaint();
	}
}
